import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/admin/home'
  },
  {
    path: '/admin',
    redirect: '/admin/home'
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/Home.vue'),
    meta: {
      title: '网站首页'
    }
  },
  {
    path: '/buyGood',
    name: 'buyGood',
    component: () => import('../views/BuyGood.vue'),
    meta: {
      title: '提交信息'
    }
  },
  {
    path: '/searchOrder',
    name: 'searchOrder',
    component: () => import('../views/searchOrder.vue'),
    meta: {
      title: '搜索订单'
    }
  },
  {
    path: '/success',
    name: 'success',
    component: () => import('../views/success.vue'),
    meta: {
      title: '提交成功'
    }
  },
  {
    path: '/admin',
    name: 'admin',
    component: () => import('../components/admin/Aside.vue'),
    children: [
      { path: 'home', component: () => import('@/views/admin/Home.vue'), meta: { title: '后台首页' } },
      { path: 'goodList', component: () => import('@/views/admin/GoodsList.vue'), meta: { title: '产品列表' } },
      { path: 'orderList', component: () => import('@/views/admin/OrdersList.vue'), meta: { title: '订单列表' } },
      { path: 'goodList/add', component: () => import('@/views/admin/AddGood.vue'), meta: { title: '新增产品' } },
      { path: 'gifGenerate', component: () => import('@/views/admin/GifGenerate.vue'), meta: { title: 'GIT生成' } },
    ],
    meta: {
      title: '后台管理'
    }
  },
  {
    path: '/admin/login',
    component: () => import('@/views/admin/Login.vue'),
    meta: { title: '后台登录' }
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})
export default router
